package priv.stones.multi_thread.runnable;

/**
 * @Author: Stones
 * @Description:
 * @Date: 2017/9/19 14:24
 */
public class Runnable1 implements Runnable {

    private String str;

    public Runnable1(String str) {
        this.str = str;
    }

    public void setStr(String str) {
        this.str = str;
    }


    private Integer ticket = 5;

    public void run() {
//        for (int i = 0; i < 10; i++) {
//            System.out.println(this.str + " run----------" + i);
//        }
        System.out.println(Thread.currentThread().getName());
        Sell();
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private synchronized void Sell() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (ticket <= 0) {
                System.out.println("票卖完了");
            } else {
                System.out.println(Thread.currentThread().getName() + "       还剩" + --ticket + "张票");
            }
        }
    }

}
